```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HashMap扩容机制深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background: #282c34;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .card {
            transition: all 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        .section-divider {
            width: 80px;
            height: 4px;
            background: linear-gradient(90deg, #6e8efb 0%, #a777e3 100%);
            margin: 2rem auto;
            border-radius: 2px;
        }
        .key-point {
            border-left: 4px solid #6e8efb;
            background-color: rgba(110, 142, 251, 0.05);
        }
        .mermaid {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:py-28">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6 font-serif">HashMap扩容机制</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90 font-serif">深入解析Java集合框架中的关键性能优化点</p>
            <div class="flex justify-center space-x-4">
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full">#Java</span>
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full">#数据结构</span>
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full">#性能优化</span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <p class="text-lg text-gray-700 leading-relaxed mb-6">
                当HashMap中的数据量增加到一定程度时，它会触发扩容操作。扩容不仅仅是增加数组的大小，还涉及到重新计算每个键的哈希值并将其重新分配到新的数组位置。这一过程被称为重新哈希（rehashing）。本文将深入解析这一关键过程的实现细节和性能影响。
            </p>
            <div class="section-divider"></div>
        </section>

        <!-- Content Sections -->
        <section class="grid md:grid-cols-3 gap-8 mb-16">
            <!-- Card 1 -->
            <div class="card bg-white">
                <div class="p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center text-blue-600">
                            <i class="fas fa-exclamation-triangle text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold ml-4">触发条件</h3>
                    </div>
                    <p class="text-gray-600">当元素数量超过负载因子（通常为0.75）与当前数组容量的乘积时触发扩容操作。</p>
                </div>
            </div>

            <!-- Card 2 -->
            <div class="card bg-white">
                <div class="p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center text-purple-600">
                            <i class="fas fa-expand-alt text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold ml-4">数组扩容</h3>
                    </div>
                    <p class="text-gray-600">创建新的数组，容量通常是旧数组的两倍，新数组的大小保持为2的幂。</p>
                </div>
            </div>

            <!-- Card 3 -->
            <div class="card bg-white">
                <div class="p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 rounded-full bg-green-100 flex items-center justify-center text-green-600">
                            <i class="fas fa-random text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold ml-4">重新哈希</h3>
                    </div>
                    <p class="text-gray-600">对于旧数组中的每个元素，重新计算其在新数组中的位置并重新分配。</p>
                </div>
            </div>
        </section>

        <!-- Rehashing Process -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 font-serif">重新哈希的过程</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-xl font-bold mb-4 text-blue-600 flex items-center">
                        <i class="fas fa-play-circle mr-2"></i> 1. 触发扩容
                    </h3>
                    <p class="text-gray-700 mb-6">当HashMap的元素数量超过负载因子（通常为0.75）和当前数组容量的乘积时，会触发扩容操作。扩容的过程包括创建一个新的更大的数组，并将旧数组中的所有元素重新分配到新数组中。</p>
                    <div class="code-block p-4 mb-6">
                        <pre class="text-gray-200 text-sm overflow-x-auto"><code>if (size > threshold) {
    resize();
}</code></pre>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-xl font-bold mb-4 text-purple-600 flex items-center">
                        <i class="fas fa-plus-circle mr-2"></i> 2. 创建新数组
                    </h3>
                    <p class="text-gray-700 mb-6">扩容操作会创建一个新的数组，其容量通常是旧数组容量的两倍。新数组的大小是2的幂，这样在计算索引时可以使用位运算提高效率。</p>
                    <div class="code-block p-4 mb-6">
                        <pre class="text-gray-200 text-sm overflow-x-auto"><code>final Node&lt;K,V&gt;[] oldTable = table;
int oldCapacity = oldTable.length;
int newCapacity = oldCapacity &lt;&lt; 1;
Node&lt;K,V&gt;[] newTable = (Node&lt;K,V&gt;[]) new Node[newCapacity];</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="mb-8">
                <h3 class="text-xl font-bold mb-4 text-green-600 flex items-center">
                    <i class="fas fa-exchange-alt mr-2"></i> 3. 重新计算哈希值并重新分配
                </h3>
                <p class="text-gray-700 mb-6">对于旧数组中的每个元素，HashMap都需要重新计算其在新数组中的位置。这是因为新数组的长度不同，哈希值的索引也需要重新计算。</p>
                <div class="code-block p-4 mb-6">
                    <pre class="text-gray-200 text-sm overflow-x-auto"><code>for (Node&lt;K,V&gt; e : oldTable) {
    while (e != null) {
        Node&lt;K,V&gt; next = e.next;
        int i = indexFor(e.hash, newCapacity);
        e.next = newTable[i];
        newTable[i] = e;
        e = next;
    }
}
table = newTable;</code></pre>
                </div>
                <p class="text-gray-700 mb-4">其中，<code class="bg-gray-100 px-1 py-0.5 rounded">indexFor(int hash, int length)</code>是用于计算数组索引的函数，通常定义为：</p>
                <div class="code-block p-4">
                    <pre class="text-gray-200 text-sm overflow-x-auto"><code>private int indexFor(int hash, int length) {
    return hash & (length - 1);
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Key Steps -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 font-serif">扩容的关键步骤</h2>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="key-point p-5 rounded-lg">
                    <h3 class="text-lg font-bold mb-3 text-blue-600 flex items-center">
                        <i class="fas fa-arrow-circle-right mr-2"></i> 创建新数组
                    </h3>
                    <p class="text-gray-700">扩容时创建一个容量更大的新数组，新数组的容量是原数组的两倍。</p>
                </div>
                
                <div class="key-point p-5 rounded-lg">
                    <h3 class="text-lg font-bold mb-3 text-purple-600 flex items-center">
                        <i class="fas fa-calculator mr-2"></i> 重新计算哈希值
                    </h3>
                    <p class="text-gray-700">对于旧数组中的每个节点，计算其在新数组中的位置。</p>
                </div>
                
                <div class="key-point p-5 rounded-lg">
                    <h3 class="text-lg font-bold mb-3 text-green-600 flex items-center">
                        <i class="fas fa-sync-alt mr-2"></i> 更新数组引用
                    </h3>
                    <p class="text-gray-700">完成所有元素的重新分配后，更新HashMap的table引用，使其指向新数组。</p>
                </div>
            </div>
        </section>

        <!-- Source Code Analysis -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 font-serif">源码分析</h2>
            
            <p class="text-gray-700 mb-6">以下是HashMap扩容和重新哈希的核心代码片段（简化版）：</p>
            
            <div class="mb-8">
                <h3 class="text-xl font-bold mb-4 text-indigo-600 flex items-center">
                    <i class="fas fa-code mr-2"></i> resize方法
                </h3>
                <div class="code-block p-4">
                    <pre class="text-gray-200 text-sm overflow-x-auto"><code>private void resize() {
    Node&lt;K,V&gt;[] oldTable = table;
    int oldCapacity = oldTable.length;
    if (oldCapacity >= MAXIMUM_CAPACITY) {
        threshold = Integer.MAX_VALUE;
        return;
    }

    int newCapacity = oldCapacity &lt;&lt; 1;
    Node&lt;K,V&gt;[] newTable = (Node&lt;K,V&gt;[]) new Node[newCapacity];
    transfer(newTable);
    table = newTable;
    threshold = (int) (newCapacity * loadFactor);
}</code></pre>
                </div>
            </div>
            
            <div>
                <h3 class="text-xl font-bold mb-4 text-indigo-600 flex items-center">
                    <i class="fas fa-code mr-2"></i> transfer方法
                </h3>
                <div class="code-block p-4">
                    <pre class="text-gray-200 text-sm overflow-x-auto"><code>private void transfer(Node&lt;K,V&gt;[] newTable) {
    Node&lt;K,V&gt;[] src = table;
    int newCapacity = newTable.length;

    for (int j = 0; j &lt; src.length; ++j) {
        Node&lt;K,V&gt; e = src[j];
        if (e != null) {
            src[j] = null;
            do {
                Node&lt;K,V&gt; next = e.next;
                int i = indexFor(e.hash, newCapacity);
                e.next = newTable[i];
                newTable[i] = e;
                e = next;
            } while (e != null);
        }
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 font-serif">可视化解析</h2>
            
            <div class="mermaid mb-8">
                graph TD
                    A[HashMap元素数量增加] --> B{是否达到扩容阈值?}
                    B -->|是| C[创建新数组: 容量翻倍]
                    B -->|否| D[继续添加元素]
                    C --> E[遍历旧数组]
                    E --> F[重新计算哈希值]
                    F --> G[确定新位置]
                    G --> H[插入新数组]
                    H --> I[全部完成?]
                    I -->|否| E
                    I -->|是| J[更新数组引用]
            </div>
            
            <div class="mermaid">
                flowchart LR
                    subgraph 扩容过程
                        A[旧数组] -->|容量不足| B(创建新数组)
                        B --> C[容量=旧数组×2]
                        C --> D[遍历旧数组]
                        D --> E[计算新哈希值]
                        E --> F[插入新数组]
                        F --> G[完成扩容]
                    end
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">深入技术细节，探索编程之美</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition-colors duration-300 flex items-center">
                        <i class="fas fa-globe mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-700 mt-6 pt-6 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```